17. Quiz: Classes in C++

Class Constructor

The constructor function of a class is a special member function that defines any input parameters or logic that must be included upon instantiation of a class. From what you've seen so far is it required to define a constructor in C++ classes?

SOLUTION: No, if undefined C++ will define a default constructor

Access Modifiers

What are the three options for access modifiers in C++?

SOLUTION: Public (access to anyone), Private (access only within the class) and Protected (access in friend classes)

Setters and Getters

Why does it make sense to specify private member variables with accessor and mutator functions, instead of public member variables?

SOLUTION: Often times you want to limit the user's access to class member variables, possibly because of an invariant.